const app = getApp();
import {
  goodsDetail
} from "../../../server/api";
Page({
  data: {
    oss_url: app.globalData.oss_url,
    serviceShow:false,
    buttons:[{text: '取消'}, {text: '拨打电话'}],
    id:'',
    goods:{},
    payNum:'',
    pic:[],
    priceS:0,
    maxDeduc:0
  },
  onLoad: function (options) {
    this.setData({
      id:options.goodsId
    })
    this.detail()
  },
  detail(){
    let data={
      id:this.data.id
    }

    goodsDetail(data).then(res=>{
      if(res.code==0){
        //多少人购买
        let num=res.data.goodsSell==null?0:res.data.goodsSell+res.data.baseSell==null?0:res.data.baseSell;
        //售价 
        let sellPrice=res.data.priceAtg-res.data.priceDeduction;
        //最高抵用
        let maxDeduc=(res.data.priceSell-res.data.priceAtg)+res.data.priceDeduction;
        //商品图片
        let pics=res.data.goodsPic.split(',');
        this.setData({
          goods:res.data,
          payNum:num,
          priceS:sellPrice,
          maxDeduc:maxDeduc,
          pic:pics,
          bigImg:pics[0]
        })
      }
    })
  },
  call(){
    this.setData({
      serviceShow:true
    })
  },
  //客服弹窗
  callService(e){   
   // console.log(e)
    let btn=e.detail.item.text;
    if(btn=='取消'){
      this.setData({
        serviceShow:false
      })
    }else{
      wx.makePhoneCall({
        phoneNumber: '4008086931' 
      })
    }
  },
  goPay(e){
    wx.navigateTo({
      url: '/pages/goodsOrder/order/index?id='+e.currentTarget.dataset.id,
    })
  }
})